package com;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.connection.jdbconnection;

public class StudentUpdate extends HttpServlet {
	
	
	private static final long serialVersionUID = 1L;
	static Connection conn=null;
	PreparedStatement pst=null;
	Statement st=null;
	ResultSet rs=null;
	String student_id=null;
	String sname=null;
	String fname=null;
	String dob=null;
	String gender=null;
	String address=null;
	String contact=null;
	String emailid=null;
	String course=null;
	String upload=null;
	String issuedate=null;
	String validuntile=null;
	String batch=null;	


	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		student_id=request.getParameter("sid");
		System.out.println(student_id);
		sname=request.getParameter("sname");
		fname=request.getParameter("fname");
		dob=request.getParameter("dob");
		System.out.println(dob);
		gender=request.getParameter("gender");
		System.out.println(gender);
		address=request.getParameter("address");
		System.out.println(address);
		contact=request.getParameter("contact");
		System.out.println(contact);
		emailid=request.getParameter("emailid");
		System.out.println(emailid);
		course=request.getParameter("course");
		System.out.println(course);
		
		batch=request.getParameter("batch");
		System.out.println(batch);
		issuedate=request.getParameter("issuedate");
		System.out.println(issuedate);
		validuntile=request.getParameter("validuntill");
		System.out.println(validuntile);
		if(student_id !=null){
			try {
				jdbconnection db=new jdbconnection();
				st=db.jdbConnection();
				String QString="Update studentform set sname='"+ sname +"',fname='"+ fname +"',dob='"+ dob +"',gender='"+ gender +"',address='"+ address +"',contact='" + contact +"',emailid='"+ emailid +"',course='"+ course +"',batch='"+ batch +"',issuedate='"+ issuedate +"',validuntile='"+ validuntile +"' where student_id ='"+ student_id + "'";
				System.out.println(QString);
				
				int a=st.executeUpdate(QString);
				System.out.println(a);
				if(a==1){
					response.sendRedirect("SuccessfullUpdate.jsp");	
				}
				else {
					response.sendRedirect("StudentForm.jsp");
				}
			}catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		
	}


	
	
}
